package com.lemeng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lemeng.entity.PageResult;
import com.lemeng.entity.Result;
import com.lemeng.pojo.Category;
import com.lemeng.service.CategoryService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("category")
public class CategoryController {


    @Reference
    CategoryService categoryService;


    @GetMapping("findAll")
    public List<Category> findAll(){
        return categoryService.findAll();
    }

    @GetMapping("findPage")
    public PageResult<Category> findPage(Integer page, Integer size) {
        return categoryService.findPage(page,size);
    }

    @PostMapping("findList")
    public List<Category> findList(@RequestBody Map<String, Object> serchMap) {
        return categoryService.findList(serchMap);
    }
    @PostMapping("findPage")
    public PageResult<Category> findPage(Integer page, Integer size,@RequestBody Map<String, Object> serchMap) {
        return categoryService.findPage(page,size,serchMap);
    }
    @GetMapping("findById")
    public Category findById(@RequestParam Integer id) {
        return categoryService.findById(id);
    }

    @PostMapping("add")
    public Result add(@RequestBody Category category) {
        categoryService.add(category);
        return new Result();
    }
    @PostMapping("update")
    public Result update(@RequestBody Category category) {
        categoryService.update(category);
        return new Result();
    }

    @GetMapping("delete")
    public Result delete(Integer id) {
        categoryService.delete(id);
        return new Result();
    }
    @GetMapping("deleteAll")
    public Result delete(String ids) {

        String[] split = ids.split(",");
        for (String id : split) {
            categoryService.delete(Integer.parseInt(id));
        }


        return new Result();
    }


}
